package com.dn.designpatterns.proxy;

/**
 * @program: designpatterns
 * @description: 代理模式
 * @author: DN
 * @create: 2021-04-01 21:58
 **/
public class ProxyPattern {

    public static void main(String[] args) {
        Proxy proxy = new Proxy();
        proxy.Request();
    }
}

// 抽象主题
interface Subject {
    void Request();
}

// 抽象实现
class RealSubject implements Subject {
    public void Request() {
        System.out.println("真实主题方法...");
    }
}

// 代理类
class Proxy implements Subject {
    private RealSubject realSubject = new RealSubject();
    private void preRequest() {
        System.out.println("request方法执行前...");
    }
    public void Request() {
        preRequest();
        realSubject.Request();
        postRequest();
    }
    private void postRequest() {
        System.out.println("方法执行后...");
    }
}